package com.shop.controller;

import com.shop.base.BaseController;
import com.shop.entity.Membership;
import com.shop.result.ResultVO;
import com.shop.service.MembershipService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author XCH
 * @date 2025 - 06 - 09
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/membership")
public class MembershipController extends BaseController {
    private final MembershipService membershipService;
    @GetMapping("/listMembership")
    public ResultVO<Object> listMembership(@RequestParam("id")Integer id) {
        List<Membership> memberships = membershipService.listMembership(id);
        return success(memberships);
    }
    @PostMapping("/updateMembership")
    public ResultVO<Object> updateMembership(Membership membership) {
        membershipService.updateMembership(membership);
        return success("更新成功");
    }
    @PostMapping("/updatePoints")
    public ResultVO<Object> updatePoints(@RequestBody Membership membership) {
        membershipService.updatePoints(membership);
        return success("更新成功");
    }
    @PostMapping("/updatePointsAndLevel")
    public ResultVO<Object> updatePointsAndLevel(@RequestBody Membership membership) {
        System.out.println("membership" + membership);
        System.out.println("empirical: " + membership.getEmpirical());
        membershipService.updatePointsAndLevel(membership);
        return success("更新成功");
    }
}
